/**
 * build_project
 * <p>
 * Copyright 2014 cayden.cn, Inc. All rights reserved.
 *
 * @author Administrator
 * @date 2021-07-08 16:07
 */
package com.cayden.base.utils;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 *
 * @author cayden
 * @date 2021-07-08 16:07
 */
public class Ports {
    public static boolean isPortUsing(int port) {
        boolean flag = false;
        InetAddress theAddress;
        try {
            theAddress = InetAddress.getByName("127.0.0.1");
        } catch (UnknownHostException e) {
            return true;
        }
        try {
            Socket socket = new Socket(theAddress, port);
            socket.close();
            flag = true;
        } catch (IOException e) {
            //do nothing
        }
        return flag;
    }
}
